#include "StdAfx.h"
#include"TException.hpp"
#include "TThreadBase.h"

void TThreadBase::MainDO()
{
	try
	{
		Do();
	}
	catch (boost::thread_interrupted&)
	{

	}
}

void TThreadBase::Start()
{
	if (IsRunning==false)
	{
		if (th==nul)
		{
			th = new boost::thread(boost::bind(&TThreadBase::MainDO, this));
		}
		else
		{
			delete th;
			th = new boost::thread(boost::bind(&TThreadBase::MainDO, this));
		}
		isCancel = false;
	}
}

void TThreadBase::Join()
{
	th->join();
}

void TThreadBase::Cancel()
{
	isCancel = true;
}

void TThreadBase::Release()
{
	if (th!=nul)
	{
		th->interrupt();
	}
}




TThreadBase::TThreadBase()
{
	th = nul;
	IsRunning = false;
}

TThreadBase::~TThreadBase()
{
	Release();
	Join();
	if (th!=nul)
	{
		delete th;
	}

}
